package com.atguigu.gmall.index.controller;


import com.atguigu.core.bean.Resp;
import com.atguigu.gmall.index.service.IndexService;
import com.atguigu.gmall.pms.entity.CategoryEntity;
import com.atguigu.gmall.pms.vo.CategoryEntityVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("index")
public class IndexController {

    /**
     * 获取首页侧边一级菜单
     */
    @Autowired
    private IndexService indexService;

    @GetMapping("cates")
    public Resp<List<CategoryEntity>> queryLvllCategories(){
        List<CategoryEntity> categoryEntities=this.indexService.queryLvllCategories();
        return Resp.ok(categoryEntities);
    }

    /**
     * 查询二三级分类
     * @param pid
     * @return
     */
    @GetMapping("cates/{pid}")
    public Resp<List<CategoryEntityVO>> querySubCategories(@PathVariable("pid")Long pid){

        List<CategoryEntityVO> categoryEntities = this.indexService.querySubCategories(pid);

        return Resp.ok(categoryEntities);

    }

    @GetMapping("test/lock")
    public String testLock(){
        this.indexService.testLock();;
        return  "ok";
    }
}
